<?php
/**
 * Created by PhpStorm.
 * User: lee
 * Date: 2018/8/9
 * Time: 17:22
 */

namespace Biz\module\Classes;

use Biz\model\ShopContactInfo as mShopContactInfo;
use Biz\model\ShopBasicInfo as mShopBasicInfo;
use Biz\tools\ShopArea as tArea;
use Doraemon\tools\Log as tLog;
use Doraemon\tools\Sms as tSms;
use Biz\model\trade\OrderPackage as mOrderPackage;


class OrderSms
{
    public static function noticeSellerNewOrder($orderShops)
    {

        array_map(function ($v) {

            $data = [];

            $contactInfos = mShopContactInfo::getShippingSpecialistInfos($v['shop_id']);

            if (!empty($contactInfos)) {

                foreach ($contactInfos as $info) {

                    $data['province'] = tArea::locationId2Name($v['province']);

                    $data['shop_name'] = mShopBasicInfo::getShopInfo($v['shop_id'], 'name');


                    tSms::sendTplMsg($info['mobile'], tSms::TYPE_NEW_ORDER_NOTICE, $data);

                    tLog::order_sendsms_info('订单支付成功短信通知商家发货', ['mobile' => $info['mobile'], 'value' => $v, 'data' => $data]);
                }


            }

        }, $orderShops);
    }

    public static function noticeNewRefundOrder($refundInfo)
    {

        $contactInfos = mShopContactInfo::getRefundCommissionerInfos($refundInfo['shop_id']);

        if (!empty($contactInfos)) {

            $data = [
                'order_no' => $refundInfo['order_no']
            ];

            foreach ($contactInfos as $info) {

                tSms::sendTplMsg($info['mobile'], tSms::TYPE_ORDER_REFUND_NOTICE, $data);

                tLog::order_sendsms_info('订单有申请退款，短信通知商家处理', ['mobile' => $info['mobile'], 'value' => $refundInfo, 'data' => $data]);
            }


        }

    }

    public static function noticeParagraphShipOrder($orderNo, $mobile, $skuNum, $packageId, $expressData)
    {
        $skuInfo = mOrderPackage::getFirstSkuInfo($orderNo, $packageId);

        $data = [
            'goods_title' => $skuNum > 1 ? $skuInfo['title'] . '等' : $skuInfo['title'],
            'express_company' => $expressData['express_company'],
            'express_no' => $expressData['express_no']
        ];

        tSms::sendTplMsg($mobile, tSms::TYPE_PARAGRAPH_ORDER_SHIP_NOTICE, $data);
    }
}